{template 'web/common/common'}
{template 'web/problem/navbar'}
<link rel="stylesheet" type="text/css" href="../addons/kundian_farm/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<div class="panel panel-success">
    <div class="panel-heading">
        <h3 class="panel-title">
            常见问题>编辑
        </h3>
    </div>
    <div class="panel-body">
        <form id="sign-form" class="form-horizontal" role="form" method="post" action="{url 'site/entry/problem',array('m'=>'kundian_farm','op'=>'problem_list_edit_save','version_id'=>$_GPC['version_id'])}" name="submit" style="padding: 20px 0;">
            <div class="form-group">
                <label class="col-sm-2 control-label">问题分类</label>
                <div class="col-sm-8">
                    <select name="parent_id" id="parent_id"  style="width: 200px;">
                        <option value="0">请选择</option>
                        {loop $typeData $index $item}
                        <option value="{$item['id']}" <?php if($parentType['id']==$item['id']){echo 'selected';}?>>{$item['type_name']}</option>
                        {/loop}
                    </select>
                    <select name="type_id" id="type_id" style="width: 200px;">
                        <option value="0">请选择</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">问题标题 问：</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control"  name="problem_title" value="{$list['problem_title']}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">问题答案 答：</label>
                <div class="col-sm-8">
                    <textarea name="problem_value" id="" cols="30" rows="10" class="form-control">{$list['problem_value']}</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">是否显示</label>
                <div class="col-sm-8">
                    {if $list['status']==1}
                    <input type="checkbox" checked class="js-switch" value="1" name="status">
                    {else}
                    <input type="checkbox" class="js-switch" name="status" value="1">
                    {/if}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">排序</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control"  name="rank" value="{$list['rank']}">
                </div>
            </div>
            <div class="form-group">

                <div class="col-sm-offset-2 col-sm-10">
                    <input type="hidden" name="id" value="{$list['id']}">
                    <input type="hidden" name="type_old_id" value="{$list['type_id']}">
                    <input type="submit" name="submit" class="btn btn-default">
                    <a class="btn btn-default" href="{url 'site/entry/problem',array('m'=>'kundian_farm','op'=>'problem_list')}">返回</a>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        $(function () {

            var id=$("input[name='id']").val();
            if(id) {
                var pid=$("#parent_id").val();
                if(pid!=0){
                    var type_id=$("input[name='type_old_id']").val();
                    $.ajax({
                        type:"post",
                        url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'getTypeData','version_id'=>$_GPC['version_id'])}",
                        data:{pid:pid},
                        dataType:'json',
                        success:function(res){
                            if(res.typeData){
                                var typeData=res.typeData;
                                var str='';
                                typeData.forEach(function (val) {
                                    if(type_id==val['id']){
                                        str+="<option value='"+val['id']+"' selected='selected'>"+val['type_name']+"</option>";
                                    }else{
                                        str+="<option value='"+val['id']+"'>"+val['type_name']+"</option>";
                                    }

                                })
                                $("#type_id").html(str);
                            }
                        }
                    })
                }

            }

            $("#parent_id").change(function () {
                var pid=$(this).val();
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'getTypeData','version_id'=>$_GPC['version_id'])}",
                    data:{pid:pid},
                    dataType:'json',
                    success:function(res){
                        if(res.typeData){
                            var typeData=res.typeData;
                            var str='';
                            typeData.forEach(function (val) {
                                str+="<option value='"+val['id']+"'>"+val['type_name']+"</option>";
                            })
                            $("#type_id").html(str);
                        }
                    }
                })
            })
        })
    })
</script>